﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NimLearning
{
	class NimMenu
	{
		public NimBoard board { get; set; }

		public NimMenu(NimBoard board)
		{
			this.board = board;

		}

		public void AskToRemove()
		{
			int result = 0;
			bool valid = false;
			Console.WriteLine("What row do you want to take from?");
			int row = 0;
			do
			{
				if (int.TryParse(Console.ReadLine(), out row))
				{
					if (row < 4 && row > 0 && board.ValidRow(row))
					{
						result = row;
						valid = true;
					}
				}

			} while (!valid);

			valid = false;
			Console.WriteLine("How many do you want to take from this row?");
			int count = 0;
			do
			{
				if (int.TryParse(Console.ReadLine(), out count))
				{
					if (count > 0 && count < board.LengthOfRow(row))
					{
						result = count;
						valid = true;
					}
				}

			} while (!valid);

			this.board.Remove(row, count);
			this.board.PrintBoard();
		}


		public int StartUp()
		{
			bool valid=false;
			int result = 0;
			Console.WriteLine("----NIM LEARNING GAME----");
			Console.WriteLine("1. Player vs AI");
			Console.WriteLine("2. AI vs AI");
			Console.WriteLine("3. Quit");
			int i=0;
			do
			{
				if (int.TryParse(Console.ReadLine(), out i))
				{
					if (i < 4 && i > 0)
					{
						result = i;
						valid = true;
					}
				}

			} while (!valid);
			
			return result;
		}
	}
}
